package com.example.user.myhjjf_app.view;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.ActivityUtils;
import com.example.user.myhjjf_app.HJJF_Url;
import com.example.user.myhjjf_app.R;
import com.example.user.myhjjf_app.model.Model_Oc;
import com.example.user.myhjjf_app.model.Model_Regional;
import com.example.user.myhjjf_app.model.Model_pt;
import com.example.user.myhjjf_app.model.Model_ptsb;
import com.example.user.myhjjf_app.presenter.MsgComingItemDelagate;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.zhy.adapter.abslistview.MultiItemTypeAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class Activity_yxsb extends AppCompatActivity {

    public Model_pt model_pt;
    String id;
    List<String> list = new ArrayList<>();
    List<Model_ptsb> model_ptsbs = new ArrayList<>();
    MultiItemTypeAdapter adapter;
    @BindView(R.id.btn_back)
    LinearLayout btnBack;
    @BindView(R.id.tx_title)
    TextView txTitle;
    @BindView(R.id.btn_menu)
    LinearLayout btnMenu;
    @BindView(R.id.list_pt_item)
    ListView listPtItem;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yxsb);
        ButterKnife.bind(this);
        id = Model_Regional.getRegional().getSiteId();
        list.add("PTN3900");
        list.add("综合传输柜");
        txTitle.setText("有线设备");
        OkGo.<String>post(HJJF_Url.getHJJF_Url().login("api/site/yx.do"))
                .tag(this)
                .params("id", id)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        model_pt = JSON.parseObject(response.body(), Model_pt.class);
                        for (int i = 0; i < model_pt.getValue().size(); i++) {
                            int a = model_pt.getValue().get(i).getSize();
                            String name = list.get(i)+" 数量:";
                            Model_ptsb ptsb = new Model_ptsb(name, a);
                            model_ptsbs.add(ptsb);
                        }
                        Model_ptsb ptsb = new Model_ptsb(list.get(list.size()-1), -1);
                        model_ptsbs.add(ptsb);
                        adapter.notifyDataSetChanged();
                    }
                });
        adapter = new MultiItemTypeAdapter(this, model_ptsbs);
        adapter.addItemViewDelegate(new MsgComingItemDelagate());
        listPtItem.setAdapter(adapter);
        listPtItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                if (i == (list.size()-1)){
                    Model_Regional.getRegional().setType("zhcsg");
                    ActivityUtils.startActivity(Activity_zhcsgAdd.class);
                    return;
                }else {
                    Model_Regional.getRegional().setType(model_pt.getValue().get(i).getType());
                }
                Model_Regional.getRegional().setName(list.get(i));
                ActivityUtils.startActivity(Activity_Pzlist.class);
            }
        });
    }
    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
